package coml.jiyun.hp.wanandroid.ui.fragment;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;

import butterknife.BindView;
import coml.jiyun.hp.wanandroid.R;
import coml.jiyun.hp.wanandroid.base.BaseLazyFragment;
import coml.jiyun.hp.wanandroid.bean.NaviBean;
import coml.jiyun.hp.wanandroid.presenter.NaviPresenter;
import coml.jiyun.hp.wanandroid.ui.adapter.FlowNaviAdapter;
import coml.jiyun.hp.wanandroid.view.NaviView;
import qdx.stickyheaderdecoration.NormalDecoration;

/**
 * A simple {@link Fragment} subclass.
 */
public class NaviFragment extends BaseLazyFragment<NaviPresenter>implements NaviView {

    @BindView(R.id.navi_rlv)
    RecyclerView mRlv;
    private ArrayList<NaviBean.DataBean> dataBeans;
    private FlowNaviAdapter flowNaviAdapter;

    public NaviFragment() {
        // Required empty public constructor
    }


    @Override
    protected void initListener() {

    }

    @Override
    protected void initData() {
        mPresenter.getNavi();
    }

    @Override
    protected NaviPresenter initPresenter() {
        return new NaviPresenter();
    }

    @Override
    protected void initView(View view) {
        mRlv.setLayoutManager(new LinearLayoutManager(getActivity()));
        dataBeans = new ArrayList<>();
        flowNaviAdapter = new FlowNaviAdapter(getActivity(), dataBeans);
        mRlv.setAdapter(flowNaviAdapter);

        NormalDecoration decoration = new NormalDecoration() {
            @Override
            public String getHeaderName(int i) {
                return dataBeans.get(i).getName();
            }
        };
        mRlv.addItemDecoration(decoration);
    }

    @Override
    protected int getLayout() {
        return R.layout.fragment_navi;
    }

    @Override
    public void setNavi(NaviBean naviBean) {
        if (naviBean != null && naviBean.getData() != null && naviBean.getData().size() > 0){
            flowNaviAdapter.addData(naviBean.getData());
            flowNaviAdapter.notifyDataSetChanged();
        }
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }
}
